//
//  Location.m
//  GNAPP
//
//  Created by zzp on 2019/1/10.
//  Copyright © 2019年 zzp. All rights reserved.
//

#import "Location.h"


@implementation Location
static Location* location = nil;
+(Location*)shareLocation{
    @synchronized(self){
        if(location == nil) {
            location = [[Location alloc] init];// assignment not done here
        }
    }
    
    location.location=[[CLLocation alloc]initWithLatitude:23.051610 longitude:113.486435];
    AMapLocationReGeocode *amap= [[AMapLocationReGeocode alloc]init];
    amap.city=@"广州";
    amap.province=@"广东";
    location.regeocode=amap;
    return location;
}

-(void)startLocation{
    // 带逆地理信息的一次定位（返回坐标和地址信息）
    if(!self.locationManager){
        self.locationManager=[[AMapLocationManager alloc]init];
        self.locationManager.delegate=self;
    }
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    //   定位超时时间，最低2s，此处设置为10s
    self.locationManager.locationTimeout =10;
    //   逆地理请求超时时间，最低2s，此处设置为10s
    self.locationManager.reGeocodeTimeout = 10;
    [self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
        
        if (error)
        {
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            
            if (error.code == AMapLocationErrorLocateFailed)
            {
                return;
            }
        }
        
        NSLog(@"location:%@", location);
        
        if (regeocode)
        {
            NSLog(@"reGeocode:%@", regeocode);
            self.latitude=location.coordinate.latitude;
            self.longtitude=location.coordinate.longitude;
            self.location=location;
            self.regeocode=regeocode;
        }
    }];
}

@end
